﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using GoogleMaps;

namespace libGoogleMapESB.Forms
{
    public partial class frmMap : Telerik.WinControls.UI.RadForm
    {
        private GoogleMapsNet googleMapsNet;
        private frmMap xx;
        public frmMap()
        {
            InitializeComponent();
            set_InitializeMap();
        }

        private void set_InitializeMap()
        {
            try
            {
                googleMapsNet = new GoogleMapsNet();
                googleMapsNet.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                googleMapsNet.Latitude = 0;
                googleMapsNet.Location = new System.Drawing.Point(this.Location.X, this.Location.Y);
                googleMapsNet.Longitude = 0;
                googleMapsNet.Name = "Eignretep Map (by Google Map) ";
                googleMapsNet.ShowGrid = false;
                googleMapsNet.Size = new System.Drawing.Size(this.Width, this.Height);
                googleMapsNet.TabIndex = 1;
                googleMapsNet.LongitudeChanged += new System.EventHandler(this.googleMapsNet_LongitudeChanged);
                googleMapsNet.LatitudeChanged += new System.EventHandler(this.googleMapsNet_LatitudeChanged);
                googleMapsNet.ZoomChanged += new System.EventHandler(this.googleMapsNet_ZoomChanged);
                googleMapsNet.Dock = DockStyle.Left;
                this.Controls.Add(googleMapsNet);

           //     panel1.Container.Add(googleMapsNet);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InitializeMap"); 
            }

            
        }

        //public void setShowRoutOnMap(string strOrigin, string strDestination)
        //{
        //    googleMapsNet.AddRoute(strOrigin, strDestination);

        //    MapType mapType = MapType.MapTypeRoadmap;
        //    mapType = MapType.MapTypeHybridTerrain;
        //    googleMapsNet.ShowMap(mapType, dblLongitude, dblLatitude, intZoom);
        //}

        public void setDisplayMap(string strOrigin, string strDestination,double dblLongitude, double dblLatitude, int intZoom)
        {
            googleMapsNet.AddRoute(strOrigin, strDestination);
            MapType mapType = MapType.MapTypeRoadmap;
            mapType = MapType.MapTypeHybridTerrain;
            googleMapsNet.ShowMap(mapType, dblLongitude, dblLatitude, intZoom);
        }

        private void frmMap_Load(object sender, EventArgs e)
        {
            
            googleMapsNet.AddressToLongitudeLatitude("Cyberjaya");
            MapType mapType = MapType.MapTypeRoadmap;
            mapType = MapType.MapTypeHybridTerrain;
            googleMapsNet.ShowMap(mapType, Convert.ToDouble("101.6573810"), Convert.ToDouble("2.9250880"), Convert.ToDouble(txtZoom.Text.Trim()));
            txtLongtitude.Text = "101.6573810";
            txtLatitude.Text = "2.9250880";

            //frmMapControls x = new frmMapControls();
            //x.setMap(ref xx);
            //x.ShowDialog(this);

           // this.MouseWheel += new MouseEventHandler(Panel1_MouseWheel);
       //     this.panel1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.Panel1_MouseWheel);

        }
        //3.862379, 101.983378

         private void googleMapsNet_LongitudeChanged(object sender, EventArgs e)
        {
                txtLongtitude.Text = googleMapsNet.Longitude.ToString();
        }

        private void googleMapsNet_LatitudeChanged(object sender, EventArgs e)
        {
              txtLatitude.Text = googleMapsNet.Latitude.ToString();
        }

           // googleMapsNet.Size = new System.Drawing.Size(this.Width, this.Height);
        private void googleMapsNet_ZoomChanged(object sender, EventArgs e)
        {

            txtZoom.Text =googleMapsNet.Zoom.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MapType mapType = MapType.MapTypeRoadmap;
            //mapType = MapType.MapTypeHybridTerrain;
            //googleMapsNet.ShowMap(mapType, Convert.ToDouble("101.6573810"), Convert.ToDouble("2.9250880"), Convert.ToDouble(txtZoom.Text.Trim()));

        }

        private void button2_Click(object sender, EventArgs e)
        {
            
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            //MapType mapType = MapType.MapTypeRoadmap;
            //mapType = MapType.MapTypeHybridTerrain;
            //int intIncrement = Convert.ToInt32(txtZoom.Text);
            
            //if (Convert.ToInt32(txtZoom.Text) + 1 >= 4 && Convert.ToInt32(txtZoom.Text) + 1 <= 15)
            //{
            //    intIncrement++;
            //    txtZoom.Text = intIncrement.ToString();
            //    googleMapsNet.ShowMap(mapType, Convert.ToDouble(txtLongtitude.Text.Trim()), Convert.ToDouble(txtLatitude.Text.Trim()), Convert.ToDouble(txtZoom.Text));
            //}
        }

        private void radButton2_Click(object sender, EventArgs e)
        {
            //MapType mapType = MapType.MapTypeRoadmap;
            //mapType = MapType.MapTypeHybridTerrain;
            //int intIncrement = Convert.ToInt32(txtZoom.Text);
            
            //if (Convert.ToInt32(txtZoom.Text) -1 >= 4 && Convert.ToInt32(txtZoom.Text) -1 <= 15)
            //{
            //    intIncrement--;
            //    txtZoom.Text = intIncrement.ToString();
            //    googleMapsNet.ShowMap(mapType, Convert.ToDouble(txtLongtitude.Text.Trim()), Convert.ToDouble(txtLatitude.Text.Trim()), Convert.ToDouble(txtZoom.Text));
            //}
        }

        private void radButton1_Click_1(object sender, EventArgs e)
        {
            MapType mapType = MapType.MapTypeRoadmap;
            mapType = MapType.MapTypeHybridTerrain;
            double dblIncrement = Convert.ToDouble(txtZoom.Text);

            if (Convert.ToInt32(txtZoom.Text) + 1 >= 4 && Convert.ToInt32(txtZoom.Text) + 1 <= 15)
            {
                dblIncrement++;
                txtZoom.Text = dblIncrement.ToString();
                googleMapsNet.ShowMap(mapType, Convert.ToDouble(txtLongtitude.Text.Trim()), Convert.ToDouble(txtLatitude.Text.Trim()), Convert.ToDouble(txtZoom.Text));
            }
        }

        private void radButton2_Click_1(object sender, EventArgs e)
        {
            MapType mapType = MapType.MapTypeRoadmap;
            mapType = MapType.MapTypeHybridTerrain;
            double dblIncrement = Convert.ToDouble(txtZoom.Text);

            if (Convert.ToInt32(txtZoom.Text) - 1 >= 4 && Convert.ToInt32(txtZoom.Text) - 1 <= 15)
            {
                dblIncrement--;
                txtZoom.Text = dblIncrement.ToString();
                googleMapsNet.ShowMap(mapType, Convert.ToDouble(txtLongtitude.Text.Trim()), Convert.ToDouble(txtLatitude.Text.Trim()), Convert.ToDouble(txtZoom.Text));
            }
        }

        //private void radHScrollBar1_Scroll(object sender, ScrollEventArgs e)
        //{
        //    try
        //    {
        //        MapType mapType = MapType.MapTypeRoadmap;
        //        mapType = MapType.MapTypeHybridTerrain;
        //        txtZoom.Text = e.NewValue.ToString();
        //        googleMapsNet.ShowMap(mapType, Convert.ToDouble(txtLongtitude.Text.Trim()), Convert.ToDouble(txtLatitude.Text.Trim()), Convert.ToDouble(txtZoom.Text.Trim()));
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message + " radHScrollBar1_Scroll"); 
        //    }
        //}

        //private void radHScrollBar1_Scroll(object sender, ScrollEventArgs e)
        //{
        //    MapType mapType = MapType.MapTypeRoadmap;
        //    mapType = MapType.MapTypeSatellite;
        //    googleMapsNet.ShowMap(mapType, Convert.ToDouble("101.6573810"), Convert.ToDouble("2.9250880"), Convert.ToDouble(e.NewValue));

        //}
    }
}
